package com.jiulong.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;



import com.alibaba.fastjson.JSONObject;
import com.jiulong.common.utils.MD5Util;
import com.jiulong.common.utils.StringUtil;
import com.jiulong.dao.TAccountMapper;
import com.jiulong.dao.TActivityMapper;
import com.jiulong.dao.TAdvertMapper;
import com.jiulong.dao.TFavoriteMapper;
import com.jiulong.dao.TGiftMapper;
import com.jiulong.dao.TNavigationMapper;
import com.jiulong.dao.TNewsMapper;
import com.jiulong.dao.TOrderMapper;
import com.jiulong.dao.TPayMapper;
import com.jiulong.dao.TProductMapper;
import com.jiulong.dao.TUserMapper;
import com.jiulong.model.TAccount;
import com.jiulong.model.TAccountExample;
import com.jiulong.model.TActivityExample;
import com.jiulong.model.TFavorite;
import com.jiulong.model.TGift;
import com.jiulong.model.TNavigationExample;
import com.jiulong.model.TNews;
import com.jiulong.model.TNewsExample;
import com.jiulong.model.TOrder;
import com.jiulong.model.TOrderExample;
import com.jiulong.model.TOrderdetail;
import com.jiulong.model.TOrderlog;
import com.jiulong.model.TOrdership;
import com.jiulong.model.TPay;
import com.jiulong.model.TProduct;
import com.jiulong.model.TUser;
import com.jiulong.model.TUserExample;
import com.jiulong.service.AccountService;
import com.jiulong.service.OrderService;
import com.jiulong.service.ProductService;
@Controller  
public class pcControl extends BaseController{
	@Autowired
	ProductService productService;
	@Autowired
	TGiftMapper tGiftMapper;
	@Autowired
	TPayMapper TPayMapper;
	@Autowired
	com.jiulong.dao.TOrderMapper TOrderMapper;
	@Autowired
	TAccountMapper tAccountMapper;
	@Autowired
	TUserMapper TUserMapper;
	@Autowired
	TProductMapper tProductMapper;
	@Autowired
	AccountService accountService;
	@Autowired
	OrderService orderService;
	@Autowired
	TOrderMapper tOrderMapper;
	@Autowired
	TFavoriteMapper tFavoriteMapper;
	@Autowired
	TNewsMapper TNewsMapper;
	@Autowired
	TNavigationMapper TNavigationMapper;
	@Autowired
	TActivityMapper TActivityMapper;
	@Autowired
	TAdvertMapper TAdvertMapper;
	//pc端未支付
	@RequestMapping("/grzxPc")
	public String grzxPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
			
		HttpSession session = request.getSession();
		String nickname=session.getAttribute("accountIsFlag").toString();
		TAccount tAccount=	accountService.findAccountbyNickname(nickname);

			String score=tAccount.getScore().toString();
			String rank=tAccount.getRank();
			model.addAttribute("rank", rank);
			model.addAttribute("score", score);
			model.addAttribute("account", nickname);
			
			List gift=orderService.findGiftbyId(nickname);
			List list=orderService.findOrderDetailByOpenid(nickname);
		 model.addAttribute("detailList", list);
		 model.addAttribute("detailGift", gift);
	
		return "grzxPc";
	}

	@RequestMapping("/grzxYijiePc")
	public String grzxYijiePc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		
		HttpSession session = request.getSession();

		String nickname=session.getAttribute("accountIsFlag").toString();
		TAccount tAccount=	accountService.findAccountbyNickname(nickname);
		 
		  String account=tAccount.getAccount();
			String score=tAccount.getScore().toString();
			String rank=tAccount.getRank();

			model.addAttribute("rank", rank);
			model.addAttribute("score", score);
			model.addAttribute("account", nickname);
			List gift=orderService.findGiftbyId(nickname);
			List list=orderService.findOrderDetailByOpenidAleadyPay(nickname);
		 model.addAttribute("detailList", list);
		 model.addAttribute("detailGift", gift);
	    System.out.println();
		return "grzxYijiePc";
	}
//支付订单
	@RequestMapping(value="/toPayPc" ,method=RequestMethod.POST)
	public String toPayPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
	
		String orderId=request.getParameter("orderId");
		if(orderId==null){
			return "error3";
		}
		System.out.println("我拿到了订单的id");
		String giftId1=request.getParameter("giftId");

		String giftprice=null;
		TGift gi=new TGift();
		if(giftId1!=null){
			try{
				int giftId=Integer.parseInt(giftId1);
			 gi=tGiftMapper.selectByPrimaryKey(giftId);
			  giftprice= String.valueOf(gi.getGiftprice())  ;
			 }catch(Exception e){
				 e.printStackTrace();
			 }
			
		}	
		System.out.println("我拿到了折扣券的优惠");
		HttpSession session = request.getSession();
	
		TOrder order=new TOrder();
		   //生成订单号
					long currentTimeMillis = System.currentTimeMillis();
				    String strReq =  currentTimeMillis + "jiulongWeiPayPc";
				    String out_trade_no = strReq; 
		order=tOrderMapper.selectByPrimaryKey(Integer.parseInt(orderId));
		String amount2=order.getAmount().toString();
		//修改订单的订单号
		 order.setRemark(out_trade_no);
	     tOrderMapper.updateByPrimaryKeySelective(order);
		double a;
		if(giftprice!=null){
		
			a=	Double.parseDouble(amount2)-Double.parseDouble(giftprice);
			a=Math.round(a*100)/100.00;
		}else{
			a=Double.parseDouble(amount2);
		}
		String amount1=String.valueOf(a);
		
		String total_fee1=String.valueOf((Double.valueOf(amount1)*100));
	     String total_fee = total_fee1.substring(0,total_fee1.indexOf("."));
	     System.out.println("我拿到了最终的生成价格的价格");
	
		String urlCode = null;
		try {
			urlCode = weixin_pay.weixin_pay(total_fee,out_trade_no);
		} catch (Exception e) {
			System.out.println("支付生成订单出错！");
			e.printStackTrace();
		}
		
 
	    String nickname=session.getAttribute("accountIsFlag").toString();
	    TAccount tAccount=	accountService.findAccountbyNickname(nickname);
		String rank=tAccount.getRank();
		String imageUrl=order.getExpressno();
		String productName=order.getExpresscode();
		String productIntroduce=order.getExpressname();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		String date=df.format(new Date());
		model.addAttribute("urlCode", urlCode);
		model.addAttribute("time", date);
		model.addAttribute("orderId", orderId);	
		model.addAttribute("productName", productName);
		model.addAttribute("productIntroduce", productIntroduce);	

		//植入销券记录
		
		if(giftId1!=null){
		try{
			TFavorite favorite=new TFavorite();
			favorite.setProductid(giftId1);
			favorite.setAccount(out_trade_no);
			tFavoriteMapper.insert(favorite);
		}catch(Exception e){
			e.printStackTrace();
		 }
		}

		return "erWeima";
	}
	@RequestMapping("/indexPc")
	public String indexPc(HttpServletRequest request,HttpServletResponse response) throws IOException{
	
		String id=request.getParameter("id");
		
		System.out.println("1"+id);
	
		return "indexPc";
	}
	//用户注册
	@RequestMapping(value="/zcPc" ,method=RequestMethod.POST)
	public String zcPc(HttpServletRequest request,HttpServletResponse response) throws IOException{
	
		String account=request.getParameter("account");
		String password=request.getParameter("newpassword");	
		String cardNO=request.getParameter("cardNo");	
		String nickname=request.getParameter("nickname");
		String tel=request.getParameter("tel");
		String email=request.getParameter("email");
		TAccount tAccount1=accountService.findAccountbyNickname(nickname);
		if(tAccount1!=null){
		String nicknameAleady=tAccount1.getNickname();
		if(nickname.equals(nicknameAleady)){
			return "errorNickNameAleady";
			}
		}
		TAccount tAccount=new TAccount();
			tAccount.setAccount(account);
			tAccount.setPassword(password);
			tAccount.setCardno(cardNO);
			tAccount.setTel(tel);
			tAccount.setEmail(email);
			tAccount.setNickname(nickname);
			tAccount.setOpenid("000000");
		  tAccountMapper.insertSelective(tAccount);
		  HttpSession session = request.getSession();
		session.setAttribute("accountIsFlag", nickname);
		return "zcSuccess";
	}
	//注册页面的进入
	@RequestMapping("/zcPc")
	public String zcPc1(HttpServletRequest request,HttpServletResponse response) throws IOException{
	
		
		return "zcPc";
	}
	@RequestMapping("/erWeima")
	public String erWeima(HttpServletRequest request,HttpServletResponse response) throws IOException{
	
	
		return "erWeima";
	}
	@RequestMapping(value="/checkPay" ,method=RequestMethod.POST)
	public void checkPay(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String isFlag="0";
		String orderId=request.getParameter("orderId");
		TOrder order=tOrderMapper.selectByPrimaryKey(Integer.parseInt(orderId));
		String isPay=order.getPaystatus();
		if(isPay.equals("y")){
			 isFlag="1";
		}
	
		JSONObject json=new JSONObject();
    	json.put("isFlag", isFlag);    	
    	System.out.println("json"+json);
    	response.setContentType("application/x-json");
    	response.setCharacterEncoding( "UTF-8" );
    	PrintWriter out=response.getWriter();
    	out.print(json.toString());

	}
	
	
	//加载页面的时候查询是否有用户信息
	@RequestMapping("/checkAccount" )
	public void checkAccount(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String isFlag="0";
		String accountIsFlag = null;
		try{
			HttpSession session = request.getSession();
			 accountIsFlag=session.getAttribute("accountIsFlag").toString();
		
			 isFlag="1";
		}catch(Exception e){
			System.out.println("没取到缓存的用户，请去登录！");
		}
		System.out.println("我进来查询用户是否登录了！"+isFlag);
		JSONObject json=new JSONObject();
    	json.put("isFlag", isFlag);
    	json.put("accountIsFlag", accountIsFlag);
    	
    	System.out.println("json"+json);
    	response.setContentType("application/x-json");
    	response.setCharacterEncoding( "UTF-8" );
    	PrintWriter out=response.getWriter();
    	out.print(json.toString());
	}
	//弹窗登录
	@RequestMapping(value="/indexPc1" ,method=RequestMethod.POST)
	public void indexPcLogin(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{


		String pwd=request.getParameter("password");
		
		String checkData=request.getParameter("account");
		
		TAccount accountCheck=new TAccount();
		accountCheck=accountService.findAccountbyData(checkData,pwd);
		String accountIsFlag=accountCheck.getNickname();
		HttpSession session = request.getSession();
		session.setAttribute("accountIsFlag", accountIsFlag);
		JSONObject json=new JSONObject();
    	json.put("validateCode", accountCheck.getNickname());
    	System.out.println("json"+json);
    	response.setContentType("application/x-json");
    	response.setCharacterEncoding( "UTF-8" );
    	PrintWriter out=response.getWriter();
    	out.print(json.toString());
	
	}

	
	
	@RequestMapping("/mapPc" )
	public String mapPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		
		return "mapPc";
	}
	@RequestMapping("/wjmmPc")
	public String wjmmPc(HttpServletRequest request,HttpServletResponse response) throws IOException, Exception{

		return "wjmmPc";
	}
	
	@RequestMapping("/xgmmPc")
	public String xgmmPc(HttpServletRequest request,HttpServletResponse response) throws IOException{
		return "xgmmPc";
	}
	//修改个人信息，记得移除缓存
	@RequestMapping(value="/xgxxGoPc" ,method=RequestMethod.POST)
	public void xgxxGoPc(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String isFlag="1";
		String nickname=request.getParameter("nickname");
		String cardno=request.getParameter("cardno");
		String tel=request.getParameter("tel");
		String passwordKey=request.getParameter("passwordKey");
		TAccount accountCheck=new TAccount();
		accountCheck=accountService.findAccountbynickName(nickname,passwordKey);

		HttpSession session = request.getSession();
		if(accountCheck!=null){
			session.removeAttribute("accountIsFlag");
			accountCheck.setNickname(nickname);accountCheck.setCardno(cardno);accountCheck.setTel(tel);
			 tAccountMapper.updateByPrimaryKey(accountCheck);
			 session.setAttribute("accountIsFlag", nickname);
		}else{
			isFlag="0";
		}
		

		JSONObject json=new JSONObject();
    	json.put("nickname", nickname);
    	json.put("cardno", cardno);
    	json.put("tel", tel);
    	json.put("isFlag", isFlag);
    	
    	System.out.println("json"+json);
    	response.setContentType("application/x-json");
    	response.setCharacterEncoding( "UTF-8" );
    	PrintWriter out=response.getWriter();
    	out.print(json.toString());
		
	}
	//修改页面的进入，这里需要回显客户的相关信息
		@RequestMapping("/xgxxPc")
		public String xgxxPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
			HttpSession session = request.getSession();
			String nickname=session.getAttribute("accountIsFlag").toString();
			TAccount account=new TAccount();
			account=accountService.findAccountbynickName(nickname,null);
			model.addAttribute("nickname", nickname);
			model.addAttribute("cardno", account.getCardno());
			model.addAttribute("tel",  account.getTel());
			
			return "xgxxPc";
		}

	@RequestMapping(value="/waitCheckdHeDui" ,method=RequestMethod.GET)
	public String waitCheckdHeDui(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
	
		return "waitCheckdHeDui";
	}
	@RequestMapping(value="/waitCheckdHeDuiZongBu" ,method=RequestMethod.GET)
	public String waitCheckdHeDuiZongBu(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
	
		return "waitCheckdHeDuiZongBu";
	}
	//分店报表查询入口
	@RequestMapping(value="/waitCheckdHeDui1" ,method=RequestMethod.POST)
	public String waitCheckdHeDui1(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
	
		String username=request.getParameter("account");
		String password=request.getParameter("password");
		String encodePassword=	MD5Util.MD5Encode(password, "utf-8");
		TUserExample example=new TUserExample();
	
		example.createCriteria().andUsernameEqualTo(username);
		List<TUser> list=TUserMapper.selectByExample(example);
	try{
		if(list.toString()=="[]"){
			return "error";
		}
		if(!encodePassword.equals(list.get(0).getPassword())){
			return "error";
		}		
	}catch(Exception e1){
		e1.printStackTrace();
	}
		
		String dateBegin=request.getParameter("dateBegin");
		String dateEnd=request.getParameter("dateEnd");
		if(dateBegin==null||dateBegin.equals("")){
			dateBegin="2000-01-01";
			dateEnd="2020-0101";
		}
		List list1 = null;
		TOrderExample example1=new TOrderExample();

		example1.createCriteria().andUserEqualTo(username).andPaystatusEqualTo("y").andCreatedateBetween(dateBegin, dateEnd);   
         long counts=tOrderMapper.countByExample(example1);
		try{	
		
		//查询符合条件的订单数量
	
         HttpSession session=request.getSession();
         session.setAttribute("counts", counts);
         session.setAttribute("username", username);
	    	 list1=orderService.findOrderDetailWithNoCheck(username,dateBegin,dateEnd);
	}catch(Exception e){
		e.printStackTrace();
	}	
		 TPay pay=TPayMapper.selectByPrimaryKey(2);
		 String payLi=pay.getSeller();
		 double payLi1=Double.parseDouble(payLi);
		 String total=orderService.findOrderDetailWithNoCheck1(username,dateBegin,dateEnd,counts);
			model.addAttribute("total", total);
		 model.addAttribute("payLi1", payLi1);	
		 model.addAttribute("username", username);	
		 model.addAttribute("detailList", list1);
		
		return "waitCheckd";
	}
	
	//总店报表查询入口
		@RequestMapping(value="/waitCheckdHeDui2" ,method=RequestMethod.POST)
		public String waitCheckdHeDui2(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		
			String username=request.getParameter("account");
			String password=request.getParameter("password");
			String encodePassword=	MD5Util.MD5Encode(password, "utf-8");
			TUserExample example=new TUserExample();
		
			example.createCriteria().andUsernameEqualTo(username);
			List<TUser> list=TUserMapper.selectByExample(example);
		try{
			if(list.toString()=="[]"){
				return "error";
			}
			if(!encodePassword.equals(list.get(0).getPassword())){
				return "error";
			}		
		}catch(Exception e1){
			e1.printStackTrace();
		}
			
			String dateBegin=request.getParameter("dateBegin");
			String dateEnd=request.getParameter("dateEnd");
			if(dateBegin==null||dateBegin.equals("")){
				dateBegin="2000-01-01";
				dateEnd="2020-0101";
			}
			List list1 = null;
			try{	
			
			//查询符合条件的订单数量
			TOrderExample example1=new TOrderExample();
			example1.createCriteria().andPaystatusEqualTo("y").andCreatedateBetween(dateBegin, dateEnd).andCarryEqualTo(1);   
	         long counts=tOrderMapper.countByExample(example1);
	         HttpSession session=request.getSession();
	         session.setAttribute("counts", counts);
		    	 list1=orderService.findOrderDetailWithNoCheck(username,dateBegin,dateEnd);
		}catch(Exception e){
			e.printStackTrace();
		}	
		    	
			 model.addAttribute("username", username);	
			 model.addAttribute("detailList", list1);
			
			return "waitCheckd";
		}
	
	
	
	

	
	@RequestMapping(value="/zcFail" ,method=RequestMethod.GET)
	public String zcFail(HttpServletRequest request,HttpServletResponse response) throws IOException{
	
		return "zcFail";
	}
	//去订单页面
	@RequestMapping(value="/ddzfPc" ,method=RequestMethod.GET)
	public String ddzfPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{

		String productId=request.getParameter("productId");
		
		//从预订页面拿来的跳转参数
		System.out.println("从预订页面拿来的跳转参数"+productId);
		TProduct product =new TProduct();
		product= tProductMapper.selectByPrimaryKey(Integer.parseInt(productId));
		BigDecimal price=product.getNowprice();
		BigDecimal yuanPrice=product.getPrice();
		String title=product.getTitle();
		String hotelName=product.getName();
		HttpSession session = request.getSession();
		session.setAttribute("productId", productId);
		session.setAttribute("price", price);	

		model.addAttribute("hotelName", hotelName);
		model.addAttribute("price", price);
		model.addAttribute("title", title);
		String nickname= session.getAttribute("accountIsFlag").toString();
		TAccount tAccount=	accountService.findAccountbyNickname(nickname);

		model.addAttribute("yuanPrice", yuanPrice);		
		String tel=tAccount.getTel();
		String cardNo=tAccount.getCardno();

		model.addAttribute("nickname", nickname);
		model.addAttribute("tel", tel);
		model.addAttribute("cardNo", cardNo);	
		
		return "ddzfPc";
	}
	
	
	
	//生成订单
	@RequestMapping(value="/ddzfPc1" ,method=RequestMethod.POST)
	public String ddzfPc1(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		String account=request.getParameter("account");
		String user=request.getParameter("user");
		String endtime1=request.getParameter("endtime1");
		String starttime1 =request.getParameter("starttime1");
		//生成订单号
		long currentTimeMillis = System.currentTimeMillis();
	    String strReq =  currentTimeMillis + "jiulongWeiPay";
	    String out_trade_no = strReq; 
		String status="init";
	
		HttpSession session = request.getSession();
		String amount1=	 session.getAttribute("price").toString();
		 String total_fee1=String.valueOf((Double.valueOf(amount1)*100));
	     String total_fee = total_fee1.substring(0,total_fee1.indexOf("."));
	
		BigDecimal amount=new BigDecimal(amount1); 
		BigDecimal fee  =new BigDecimal(0);
		BigDecimal ptotal  =amount ;
		int quantity  =1;
		String 	paystatus= "n";
		String updateAmount="n";
		TOrder order=new TOrder();
	
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			String date=df.format(new Date());
			System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
			try{	order.setCreatedate(date);}catch(Exception e){
				e.printStackTrace();
			}
	
		order.setAccount(account);
		order.setUser(user);
		order.setEndtime1(endtime1);
		order.setStarttime1(starttime1);
		order.setStatus(status);
		order.setAmount(amount);
		order.setFee(fee);
		order.setPtotal(ptotal);
		order.setQuantity(quantity);
		order.setPaystatus(paystatus);
		order.setUpdateamount(updateAmount);
		String productId= session.getAttribute("productId").toString();
		TProduct product =new TProduct();
		product= tProductMapper.selectByPrimaryKey(Integer.parseInt(productId));
		String productName=product.getName();
		String productIntroduce=product.getIntroduce();
		String imageUrl1=product.getPicture();
		String imageUrl="http://threeshop1.oss-cn-hangzhou.aliyuncs.com"+imageUrl1;
		//expresscode:此处作为产品名字
		order.setExpresscode(productName);
		//expressno:图片路径
		order.setExpressno(imageUrl);
		//expressnname:产品介绍
		order.setExpressname(productIntroduce);
		//remark：此处作为订单号的记录
		order.setRemark(out_trade_no);
		orderService.insertOrder(order);
		int orderId = 0;
	try{
		//获取订单id
		TOrderExample example=new TOrderExample();
		example.createCriteria().andRemarkEqualTo(out_trade_no);
		List<TOrder> orderList=TOrderMapper.selectByExample(example);
		orderList=TOrderMapper.selectByExample(example);
	    orderId=orderList.get(0).getId();
	}catch(Exception e){
		System.out.println("获取订单id异常！");
		e.printStackTrace();
	}
	//开始插入订单信息
		try{
	
		TOrderdetail detail=new TOrderdetail();
		detail.setOrderid(orderId);

		orderService.insertOrderDetail(detail);
		}catch(Exception sql){
			System.out.println("插入详细订单信息异常！");
			sql.printStackTrace();
		}

		
		
	String nickname=	session.getAttribute("accountIsFlag").toString()	;
		//String openid="ohx_wwiIXSM7yFNDcaLymiMeIh9o";
		
		
	TAccount tAccount=	accountService.findAccountbyNickname(nickname);
	String score=tAccount.getScore().toString();
	String rank=tAccount.getRank();

	model.addAttribute("rank", rank);
	model.addAttribute("score", score);
	model.addAttribute("account", account);	

	try{	
		//插入用户的信息
		TOrdership ship=new TOrdership();
		ship.setOrderid(String.valueOf(orderId));
		//查询手机号码和nickname
		ship.setPhone(tAccount.getTel());
		ship.setShipname(nickname);
		//remark作为入住日期
		ship.setRemark(starttime1);
		//tel作为离店日期
		ship.setTel(endtime1);
		//开始插入订单信息
			orderService.insertOrderShip(ship);
			}catch(Exception sql){
				System.out.println("插入详细订单ship信息异常！");
				sql.printStackTrace();
			}

	//插入日志信息
	try{
		TOrderlog log=new TOrderlog();
		log.setOrderid(String.valueOf(orderId));
		log.setAccount(nickname);
		log.setAccounttype("w");
		Calendar c = Calendar.getInstance();
		Date nowTime = c.getTime();
		System.out.println(nowTime);
		log.setCreatedate(nowTime);	
		log.setContent("【创建订单】用户创建订单。订单总金额："+amount);
		orderService.insertOrderLog(log);
	}catch(Exception e){
		System.out.println("订单日志插入失败！");
		e.printStackTrace();
	}
		
	try{
	List gift=orderService.findGiftbyId(nickname);
	
	List list=orderService.findOrderDetailByOpenid(nickname);
	model.addAttribute("detailList", list);
	 model.addAttribute("detailGift", gift);
	}catch(Exception e){
		e.printStackTrace();
	}
		return "grzxPc";
	}
	
	//添加条件的查询
	@RequestMapping(value="/kfydPc",method=RequestMethod.POST)
	public String postkfyd(String city,String startDate,String endDate,String breakfirst,String park,String meettingRoom,String wifi,String visitor,HttpServletRequest request,HttpServletResponse response,Model model) throws IOException, ParseException{
	        
		String title="";
		String city1=null;
		String city2="";
		String check="北京|上海|天津|重庆";
		if(!StringUtil.isBlank(city)){
			String c[]=city.split("/");
			city=c[0];	
			city1=c[1];
			
			if(check.indexOf(city)==-1) {
				city2=c[2];
			}	
			
			try{
			if(city.length()>2){
				city=city.substring(0, 2);
			}
			}catch(Exception e){
				e.printStackTrace();
			}
		}else{
			return "kfydPc";
		}
		Date sd=null;
		Date ed=null;
		if(!StringUtil.isBlank(startDate)&&!StringUtil.isBlank(endDate)){
			SimpleDateFormat sdf2  = new SimpleDateFormat("yyyy-MM-dd");
			sd=sdf2.parse(startDate);
			ed=sdf2.parse(endDate);
		}
		
		HashMap param=new HashMap();
		param.put("city", city);
		param.put("title", title);
		param.put("city1", city1);
		param.put("city2", city2);
		param.put("startDate",sd);
		param.put("endDate", ed);
		
/*		param.put("breakfirst", breakfirst);
		param.put("park", park);
		param.put("meettingRoom", meettingRoom);
	param.put("wifi", wifi);
		param.put("visitor", visitor);*/
		
		Object o=breakfirst!=null?param.put("breakfirst",breakfirst.equals("on")?1:0):param.put("breakfirst", 0);
		o=park!=null?param.put("park",park.equals("on")?1:0):param.put("park", 0);
		o=meettingRoom!=null?param.put("meettingRoom",meettingRoom.equals("on")?1:0):param.put("meettingRoom", 0);
		o=wifi!=null?param.put("wifi",wifi.equals("on")?1:0):param.put("wifi", 0);
		o=visitor!=null?param.put("visitor",visitor.equals("on")?1:0):param.put("visitor", 0);
		
		List list=productService.findProductBysele(param);
		model.addAttribute("detailList", list);
	    List list1=productService.findProductTobeLow();
        TProduct p=(TProduct) list1.get(0);
        model.addAttribute("nowprice", p.getNowprice());
		return "kfydPc";
	}
	
	
	//没有添加条件的查询
	@RequestMapping("/kfydPc")
	public String kfydPc1(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{

        List list=productService.findProductByDefault(null);
        List list1=productService.findProductTobeLow();
        TProduct p=(TProduct) list1.get(0);
        
        model.addAttribute("detailList", list);
        model.addAttribute("nowprice", p.getNowprice());
        	return "kfydPc";
	}
	//文章编辑
	@RequestMapping("/jdxgPc")
	public String jdxgPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		TNewsExample example=new TNewsExample();
		example.createCriteria().andStatusEqualTo("y").andTypeEqualTo("help");
		List list=TNewsMapper.selectByExample(example);
		TNewsExample example1=new TNewsExample();
		example1.createCriteria().andStatusEqualTo("y").andTypeEqualTo("help");
		 TNews news=TNewsMapper.selectByExample(example1).get(0);
		 model.addAttribute("title2", news.getTitle2());
        model.addAttribute("detailList", list);
		return "jdxgPc";
	}
	//文章编辑
		@RequestMapping("/contentText")
		public String contentText(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{
			
			String contentText=new String(request.getParameter("content").getBytes("ISO-8859-1"),"UTF-8");
			TNewsExample example=new TNewsExample();
			TNewsExample example1=new TNewsExample();
			example1.createCriteria().andStatusEqualTo("y").andTypeEqualTo("help");
			example.createCriteria().andTitleEqualTo(contentText).andStatusEqualTo("y").andTypeEqualTo("help"); 
			List list=TNewsMapper.selectByExample(example1);
	       TNews news=TNewsMapper.selectByExample(example).get(0);
	        model.addAttribute("detailList", list);
	        model.addAttribute("title2", news.getTitle2());
	        System.out.println(news.getContent());
	        	return "jdxgPc";
		}
		//视频编辑
		@RequestMapping("/jtspPc")
		public String jtspPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
			TNavigationExample example=new TNavigationExample();
			List list=TNavigationMapper.selectByExample(example);
			model.addAttribute("detailList", list);
			return "jtspPc";
		}
		
		//活动
		@RequestMapping("/yhhdPc")
		public String yhhdPc(HttpServletRequest request,HttpServletResponse response,Model model) throws IOException, ParseException{
			TActivityExample example=new TActivityExample();
			example.createCriteria().andActivitytypeEqualTo("c").andStatusEqualTo("y");
			List list=TActivityMapper.selectByExample(example);		
			model.addAttribute("detailList", list);	
			return "yhhdPc";
		}
	
}
